package com.acme.wave.robot.parroty;

import com.google.wave.api.*;

public class DebugServlet extends AbstractRobotServlet {

    @Override
    public void processEvents(RobotMessageBundle bundle) {
        Wavelet wavelet = bundle.getWavelet();

        if (bundle.wasSelfAdded()) {
            Blip blip = wavelet.appendBlip();
            TextView textView = blip.getDocument();
            textView.append("Hi. Type 'Debug' in a blip to get some info.");
        }

        for (Event e : bundle.getEvents()) {
            if (e.getType() == EventType.BLIP_SUBMITTED &&
                "debug".equalsIgnoreCase(e.getBlip().getDocument().getText().trim())
                ) {
                Blip blip = e.getBlip().createChild();
                TextView textView = blip.getDocument();
                textView.append("\nDebug info:\n");
                textView.append("\tBlip ID: " + e.getBlip().getBlipId()+"\n");
                textView.append("\tWavelet ID: " + e.getBlip().getWavelet().getWaveletId()+"\n");
                textView.append("\tWave ID: " + e.getBlip().getWavelet().getWaveId()+"\n");
                textView.append("\tTitle: " + e.getBlip().getWavelet().getTitle()+"\n");
                //textView.append("\tEvent content: " + e.getBlip().getDocument().getText());
            }
        }
    }
}